<?php

namespace Addons\Jinuser\Controller;
use  Addons\Jinuser\Controller\BaseController;
class JinuserController extends BaseController{
        function lists() {
		$normal_tips = '这个主要用来添加不同场景的分组的，也可以区分不同的公众号';
		$this->assign ( 'normal_tips', $normal_tips );
		
		parent::lists ();
	}
    
        function preview() {
		$param ['test_id'] = I ( 'id', 0, 'intval' );
		$url = addons_url ( 'Jinuser://Wapuser/index', $param );
		// dump($url);
		//redirect ( $url );
		$this->assign('url', $url);
		$this->display(SITE_PATH . '/Application/Home/View/default/Addons/preview.html');
	}
    
    
      /**
	 * 显示分组
	 */
	public function index($siteid = 1, $columnid = 2) {
               
		$list = $this->getcategory($siteid, $columnid);
                
		if($list){
			foreach($list as $key=>$val){
				$repath = str_replace(',','-',$val['parentpath']).'-'.$val['id'];
				$list[$key]['repath'] = $repath;
				/*根目录*/
				if($val['pid'] == 0){
					if($val['childnum'] == 0){
						$list[$key]['tree'] = '<a href="javascript:void(0);" class="btn-toolbar">
											   <span id="tree-'.$val['id'].'" class="fa fa-minus"></span></a>';
					}else{
						$list[$key]['tree'] = '<a href="javascript:void(0);" class="btn-toolbar" onClick="showhidetr(\''.$repath.'\','.$val['id'].');">
											   <span id="tree-'.$val['id'].'" class="fa fa-minus"></span></a>';
					}
					$list[$key]['img'] = '';
				}else{
					$list[$key]['tree'] = '&nbsp;';
					$img = '';
					if($val['level'] > 1){
						$img = '<img src="Public/img/cate2.gif"> ';
						for($i=2; $i<$val['level']; $i++){
							$img = '<img src="Public/img/cate1.gif">'.$img;
						}
					}
					$list[$key]['img'] = $img;
				}
			}
		}
		$this->assign('list', $list); 
		$this->assign('siteid', $siteid);
		$this->assign('columntitle', $columntitle);
		$this->assign('columnid', $columnid);
		$this->assign('funcpath', $funcpath);
		$this->display();
	}
	
	function  categoryadd(){
		$lp = I('post.lp', 0);
		$pid = I('get.pid', 0);
		$level = I('get.level', 0);
		$parentpath = I('get.parentpath', '0');
		$repath = str_replace(',','-',$parentpath).'-';
		$img = '';
		$tree = '';
		if($level==1){
			$tree = '<a href="javascript:void(0);" class="btn-toolbar"> <span id="tree-4" class="fa fa-minus"></span></a>';
		}else{
			if($level > 1){
				$img = '<img src="Public/img/cate2.gif"> ';
				for($i=2; $i<$level; $i++) $img = '<img src="Public/img/cate1.gif">'.$img; 
			}
		}
		$html = '<tr class="list-'.$repath.' newlist">
				  <td class="hidden-phone">#<input name="lp[]" type="hidden" value="'.$lp.'"></td>
				  <td><input type="text" name="nnosort'.$lp.'" datatype="n" value="0" class="input-block-level" style="width:40px;"></td>
				  <td>'.$tree.'</td>
				  <td>'.$img.'<input type="text" name="nname'.$lp.'" value="" datatype="*" >
				  	<input name="nlevel'.$lp.'" type="hidden" value="'.$level.'">
				  	<input name="npid'.$lp.'" type="hidden" value="'.$pid.'">
				  	<input name="nparentpath'.$lp.'" type="hidden" value="'.$parentpath.'">
					<a href="javascript:void(0);" onClick="delettr($(this));" class="text-error"><span class="fa fa-times"></span> 删除</a></td>
				  <td>&nbsp;</td>
				</tr>';
		echo $html;
	}
        function config(){
            $normal_tips = '如需用户关注时提示先绑定，请进入‘欢迎语’插件按提示进行配置提示语';
            $this->assign ( 'normal_tips', $normal_tips );
            parent::config();
        }
                
       
	
        function categorymod($siteid,$columnid,$id){
		if(IS_POST){
			$category = M('category');
			$data =I('post.'); 
			if($data){
				$data['title'] = trim($data['title']) == '' ? '-' : trim($data['title']);
				$data['details'] = trim($data['details']) == '' ? '-' : trim($data['details']);
                              
				$category ->save($data); 
				S('category'.$siteid.$columnid, null);
				$this->Success('恭喜：保存分类信息成功', I('post.backurl'));
			}else{
				$this->Error('提示：未提交数据');
			}
		}else{
			$rs = M('category')->Find($id);
			if($rs){
				$rs['title'] = $rs['title'] == '-' ? '' : $rs['title'];
				$rs['details'] = $rs['details'] == '-' ? '' : $rs['details'];        
			}
			$this->assign('rs', $rs);
			$this->assign('backurl', addons_url('Jinuser://Jinuser/lists'));
			$this->display();
		}
	}
        
    
}
